package com.xcity.robot.net.util;

import com.xcity.game.account.Platform;
import com.xcity.pomelo.request.LoginRequest;
import com.xcity.robot.net.Session;
import com.xcity.robot.net.handler.LoginResponseHandler;
import com.xcity.robot.net.websocket.HandshakeListener;

import naga.x.util.CommonUtils;

public class Settings {

	public static HandshakeListener pomeloHandshakeListener;
	
	// the default settings
	static {
		pomeloHandshakeListener = new HandshakeListener() {
			@Override
			public void handshakeOk(Session session) {
				LoginRequest req = new LoginRequest();
//				private String userName;
				req.setUserId(CommonUtils.randomText(8));
//				private String userId; // @see User#channelUid
//				req.setUserName("__x" + CommonUtils.randomText(3));
				req.setUserName(NameBuilder.nextName());
//				private String ip;
				req.setIp("localhost");
//				private String channel;
				req.setChannel("1");
				req.setPlatform(Platform.ANDROID.ordinal());
				req.setSerial(SessionUtils.nextSerial(session));
				session.write(req, LoginResponseHandler.DEFAULT);
			}
		};
	}
	
	public static class NameBuilder {
		static int n = 1;
		public static synchronized String nextName() {
			return "_x_" + ++n;
		}
	}
	
	
}
